﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}


<div id="eq-operate">
    <div class="mdui-appbar mdui-color-white mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar">
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>

            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>

            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div id="xd-appbar" class="mdui-appbar mdui-color-white mdui-shadow-1">
    <div class="mdui-toolbar">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <div class="mdui-toolbar-spacer"></div>


        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>


    </div>
</div>
<div class="mdui-container-fluid mdui-m-t-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>

@section Scripts{
    <script>

        @{
            var DbBackupType = Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.SystemSecurity.DbBackupType));
        }

        var DbBackupType='@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(DbBackupType))';

        $(function () {
            gridTable();
        });


        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.dataGrid({
                url: '/SystemSecurity/DbBackup/IndexGridJson',
                mtype: "GET",
                datatype: "json",
                sortname: 'CreateTime',
                sortorder: 'DESC',
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden: true },
                    { label: 'OrganizeBelongType', name: 'TheBuildCompany.OrganizeBelongType',  hidden: true },
                    { label: '文件名称', name: 'FileName', width: 150, sortable:false },

                    { label: '文件大小', name: 'FileSize', width: 100, sortable: false },
                    { label: '文件路径', name: 'FilePath', width: 150, sortable: false },
                    {
                        label: '备份类型', name: 'DbBackupType', width: 100, formatter: function (cellValue) {
                            return $.GetEnumText(cellValue, DbBackupType);
                        }
                    },
                    {
                        label: '备份时间', name: 'BackupTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    },
                    {
                        label: '创建时间', name: 'CreateTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    }

                ],
                viewrecords: true,
                height: getGridHeight() - 34,
                rowNum: 20,
                shrinkToFit: true,
                pager: "#gridPager"
            });

            $('#refreshBtn').click(function () {
                window.location.reload();
            });


        }

        function btn_help() {
            top.$.modalAlert('自动备份请在<b class="mdui-text-color-theme">【定时任务调度】</b>中配置查看。');
        }

        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建备份',
                url: '/SystemSecurity/DbBackup/Create',
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_config() {
            $.modalOpen({
                id: 'formCreate',
                title: '数据备份配置',
                url: '/SystemSecurity/DbBackup/Config',
                width: '500px',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_download() {
            var id = $('#gridTable').jqGridRowValue().Id;
            //top.$.download("/SystemSecurity/DbBackup/Download", "id=" + id, 'post');
            window.open('/SystemSecurity/DbBackup/Download?id='+id);
        }


        function btn_details() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemSecurity/DbBackup/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }


        function btn_delete() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                url: '/SystemSecurity/DbBackup/DeleteSubmit?id=' + key,
                param: {},
                success: function () {
                    window.location.reload();
                }
            })
        }
    </script>
}
